package com.hulizuofang.wol.chat.client.ui.chat;

import java.util.Set;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.inject.Inject;
import com.hulizuofang.wol.chat.client.data.ChatUser;
import com.hulizuofang.wol.chat.client.gin.ComponentFactory;
import com.hulizuofang.wol.chat.client.ui.user.ChatUserPanel;

public class WhoisOnlinePanel extends Composite {

	private SimplePanel container;
	private VerticalPanel verticalPanel;
	private final ComponentFactory componentFactory;

	@Inject
	public WhoisOnlinePanel(ComponentFactory componentFactory) {
		this.componentFactory = componentFactory;
		container = new DecoratorPanel();
		verticalPanel = new VerticalPanel();

		container.add(verticalPanel);
		initWidget(container);
	}

	public void refreshOnlineUser(Set<ChatUser> users) {
		// TODO as for now we add users but we do not remove them
		// verticalPanel.clear();
		if (users != null)
			for (ChatUser user : users) {
				ChatUserPanel chatUserPanel = componentFactory
						.newChatUserPanel(user);
				verticalPanel.add(chatUserPanel);
			}
	}

}
